<?php

declare(strict_types=1);

namespace App\Api\Controller;

use App\Api\Middleware\ApiLockMiddleware;
use App\Api\Middleware\CheckAuthMiddleware;
use App\Api\Middleware\ResponseMiddleware;
use App\Api\Request\AdminRequest;
use App\Api\Service\AdminService;
use App\Model\Order;
use App\System\Model\SystemUser;
use Hyperf\Database\Model\Collection;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;

#[Controller(prefix: 'api'), Middlewares([ResponseMiddleware::class])]
class AdminController
{
    /**
     * 登录
     * @param AdminRequest $request
     * @param AdminService $service
     * @return array
     */
    #[PostMapping('admin/login'), Middlewares([ApiLockMiddleware::class])]
    public function login(AdminRequest $request, AdminService $service): array
    {
        return $service->login($request->validated());
    }

    /**
     * 获取管理员信息
     * @param AdminService $service
     * @return SystemUser
     */
    #[GetMapping('admin/personal'), Middlewares([CheckAuthMiddleware::class])]
    public function personal(AdminService $service): SystemUser
    {
        return $service->personal();
    }

    // 订单列表
    #[GetMapping('admin/orders'), Middlewares([CheckAuthMiddleware::class])]
    public function orderIndex(AdminService $service)
    {
        return $service->orderIndex();
    }

    /**
     * 订单详情
     * @param mixed $id
     * @param AdminService $service
     * @return Order
     */
    #[GetMapping('admin/orders/{id}'), Middlewares([CheckAuthMiddleware::class])]
    public function orderShow(mixed $id, AdminService $service): Order
    {
        return $service->orderShow($id);
    }

    /**
     * 员工选择列表
     * @param AdminService $service
     * @return array
     */
    #[GetMapping('admin/staffs'), Middlewares([CheckAuthMiddleware::class])]
    public function staffDict(AdminService $service): array
    {
        return [
            'list' => $service->staffDict(),
        ];
    }

    /**
     * 分配员工
     * @param mixed $id
     * @param mixed $staffId
     * @param AdminService $service
     * @return void
     */
    #[PutMapping('admin/orders/{id}/assign_staff/{staffId}'), Middlewares([CheckAuthMiddleware::class, ApiLockMiddleware::class])]
    public function updateOrderAssignStaff(mixed $id, mixed $staffId, AdminService $service): void
    {
        $service->updateOrderAssignStaff($id, $staffId);
    }
}
